/**
 * Created by zhaocong on 2016/4/11.
 */

//每次都能忘掉的单词  arguments

/*
 * @func 测试原型模式
 * */
//function Person(){
//}
//Person.prototype.name = "Nicholas";
//Person.prototype.age = 29;
//Person.prototype.job = "Software Engineer";
//Person.prototype.sayName = function(){
//  alert(this.name);
//};
//var person1 = new Person();
//var person2 = new Person();
//person1.name = "Greg";
//alert(person1.name); //"Greg"——来自实例
//alert(person2.name); //"Nicholas"——来自原型

// 添加新属性
//Object.defineProperty(Person, "newDataProperty", {
//  value: 101,
//  writable: true,
//  enumerable: true,
//  configurable: true
//});

//function Person(){
//}
//Person.prototype = {
//  name : "Nicholas",
//  age : 29,
//  job: "Software Engineer",
//  sayName : function () {
//    alert(this.name);
//  }
//};
//
//var friend = new Person();
//friend.sayName();
//
//
//// 为string 添加方法  -- 并不推荐
//String.prototype.startsWith = function (text) {
//  return this.indexOf(text) == 0;
//};
//var msg = "Hello world!";
//alert(msg.startsWith("Hello")); //true


// 这才是为师的完全体 - 组合构造函数和原型模式
function Person(name, age, job){
  this.name = name;
  this.age = age;
  this.job = job;
  this.friends = ["Shelby", "Court"];
}
Person.prototype = {
  constructor : Person,
  sayName : function(){
    alert(this.name);
  }
};
var person1 = new Person("Nicholas", 29, "Software Engineer");
var person2 = new Person("Greg", 27, "Doctor");
person1.friends.push("Van");
person1.sayName();
alert(person1.constructor);
//alert(person1.friends); //"Shelby,Count,Van"
//alert(person2.friends); //"Shelby,Count"
//alert(person1.friends === person2.friends); //false
//alert(person1.sayName === person2.sayName); //true

//禁止默认事件和冒泡
e.stopPropagation();
e.preventDefault();